<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>后台</title>
		<link rel="stylesheet" href="/static/admin/css/dashicons.css">
		<link rel="stylesheet" href="/static/admin/css/style.css">
	</head>
	<body>
		<div class="wrap wrap-article">
			<h1>文章管理</h1>
			<div class="s-nav">
				<div>
					<form method="POST" enctype="article" >
						<select name="category_id">
							<option value="0"  >无</option>
							{foreach $data as $k=>$v}
							<option value="{$v.id}"  {if $category_id == $v.id} selected {/if} >{$v.name}</option>
								{if isset($v.child)}
									{foreach $v.child as $val}
							<option value="{$val.id}"  {if $category_id == $val.id} selected {/if}>—— {$val.name}</option>
									{/foreach}
								{/if}
							{/foreach}
						</select>
						<select name="order" >
							<option value="time-asc"  {if $order == "time-asc" } selected {/if}>时间降序</option>
							<option value="time-desc"  {if $order == "time-desc" } selected {/if}>时间升序</option>
							<option value="show-desc"  {if $order == "show-desc" } selected {/if}>发布状态</option>
						</select>
						<input type="text" name="keywords" value="{$keywords}"  placeholder="输入标题关键字">
						<input type="submit" value="搜索文章">
					</form>
				</div>
			</div>

			<div class="tips"></div>
			<div class="box">
				<div class="box-body">
					<table>
						<tr>
						<th width="80">状态</th>
						<th>文章标题</th>
						<th width="120">所属栏目</th>
						<th width="100">作者</th>
						<th width="150">创建时间</th>
						<th width="150">操作</th>
						</tr>
						{volist name="list" id="vo"}
						<tr>
							<td class="s-show">
								{if $vo.save == 1}
									<i class="icon-yes">已发布</i>
								{else/}
									<i class="icon-wait" >未发布</i>
								{/if}
							</td>
							<td class="s-title"><a href="http://www.cms.com/index.php/home/index/show.html?id={$vo.id}" target="_blank">{$vo.title}</a></td>
							<td ><a href="http://www.cms.com/index.php/home/index/list.html?cid={$vo.category.id}"  target="_blank">[{$vo.category.name}]</a></td>
							<td>{$vo.user.username}</td>
							<td>{$vo.create_time}</td>
							<td class="s-act">
							<a href="JavaScript:void(0)"  onclick="newest({$vo.id},this)">
								{$vo.is_newest == 1 ? '取消热门' : '热门'}
							</a>
							<a href="cp_article_edit_2.html?id={$vo.id}" >编辑</a>
							<a href="article_del.html?id={$vo.id}" class="jq-del">删除</a></td>
						</tr>
						{/volist}
					</table>
				</div>
				{$list|raw}
			</div>
	</body>
</html>
<script src="/static/admin/js/jquery.2.1.4.min.js"></script>

<script>
	(function () {
		//删除前提示
		$(".jq-del").click(function () {
			return confirm("您确定要删除此文章？");
		});
	})();
	//热门
	function newest(id,self){
		console.log(id);
		$.ajax({
			url:'newest',
			type:'POST',
			data:{
				id:id,
			},
			success:function (res){
				if(res.code == 1){
					$(self).html('取消热门').attr('onclick',`ontNew(${id},this)`).attr('style','color:pink');
				}else{
					alert(res.msg);
				}
			}
		})
	}
	//取消热门
	function ontNew(id,self){
		$.ajax({
			url:'onnew',
			type:'POST',
			data:{
				id:id,
			},
			success:function (res){
				if(res.code == 1){
					$(self).html('热门').attr('onclick',`newest(${id},this)`).attr('style','color:#0073aa');
				}else{
					alert(res.msg);
				}
			}
		})
	}
</script>